//app.js
const api = require('./api.js');
App({
    onLaunch: function(options) {
        let that = this;
        wx.getSystemInfo({
            success: function(res) {
                // console.log(res.SDKVersion)
                if (res.SDKVersion > '1.9 .0') {
                    const updateManager = wx.getUpdateManager()
                    updateManager.onCheckForUpdate(function(res) {
                        // console.log(res.hasUpdate)
                    })
                    updateManager.onUpdateReady(function() {
                            wx.showModal({
                                title: '更新提示',
                                content: '新版本已经准备好，是否马上重启小程序？',
                                success: function(res) {
                                    // console.log(res.confirm)
                                    if (res.confirm) {
                                        updateManager.applyUpdate()
                                    }
                                }
                            })
                        })
                        // 失败
                    updateManager.onUpdateFailed(function() {})
                }
            }
        });
        wx.getSetting({
            success: res => {
                if (res.authSetting['scope.userInfo'] != undefined && res.authSetting['scope.userInfo'] != true) {} else {
                    that.ifuserinfo(res);
                };
            }
        });
    },
    ifuserinfo() {
        let that = this;
        var kgame = wx.getStorageSync('kgame');
        var userInfo = wx.getStorageSync('userInfo');
        var weapp_openid = wx.getStorageSync('weapp_openid');
        if (kgame && userInfo && weapp_openid && weapp_openid == userInfo.openId) {
            that.globalData.accredit = true
        }
    },
    globalData: {
        accredit: false, //是否授权
    },
})